<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取元素内容</title>
</head>
<body>
    <input type="text" id="username" name="username" placeholder="请输入您的用户名">
    <hr>
    <button onclick="dom01()">通过id获取元素内容</button>
    <button onclick="dom02()">通过name获取元素内容</button>
</body>
    <script>
        function dom01(){
            var obj = document.getElementById("username")
            alert(obj.value)

            obj.value = "小明"
        }
        function dom02(){
            var obj = document.getElementsByName("username")[0]
            alert(obj.value)
            obj.value = "小明"
        }
    </script>
</html>